package web.servlet.owner;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import service.OwnerServiceImpl;
import util.UUIDUtil;
import domain.Owner;

public class AddOwnerServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		//获取表单数据
		Owner owner = new Owner();
		try {
			BeanUtils.populate(owner, request.getParameterMap());
			owner.setOwnerId(UUIDUtil.getUUID());//手动生成一个随机ID
		} catch (Exception e) {
			e.printStackTrace();
		}
		//调用业务逻辑
		OwnerServiceImpl os = new OwnerServiceImpl();
		os.addOwner(owner);
		
		//分发转向
									//不写/代表相对路径，相对于本类的路径
		request.getRequestDispatcher("ownerListServlet").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
